// pages/setting/setting.js
import {
  saveStringToFile
} from "../../utils/util";
import { USER_FILE_NAME } from "../../constant/constant";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    source: "12 <a href=\"https://my.oschina.net/u/1272314\" class=\"referer\">@胖达panda</a> :789 [发呆[发呆]:bowtie:"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  toAboutUs: function () {
    wx.navigateTo({
      url: '/pages/about/about',
    });
  },

  exitLogin: function () {
    var that = this;
    wx.showModal({
      content: '您确定要退出登录吗？',
      success: function (res) {
        if (res.confirm) {
          that.clearLoginData();
        } else if (res.cancel) {

        }
      }
    });
  },

  clearLoginData: function () {
    var app = getApp();
    app.globalData.userInfo = null;
    app.globalData.userId = '';
    app.globalData.isLogin = false;
    app.globalData.cookieStr = '';
    wx.removeStorageSync('cookie');
    wx.removeStorageSync('userId');
    saveStringToFile('', USER_FILE_NAME);
    var pages = getCurrentPages();
    var prePage = pages[pages.length - 2];
    prePage.setData({
      reload: true,
    });
    wx.navigateBack({
      delta: 1,
    });
  },

})